<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('工时表(月汇总)')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>时间：</label>
                                <input type="text" data-type="month" class="time-input" placeholder="请选择时间" name="month" id="month"/>
                            </li>
                            <li>
                                <label>编码：</label>
                                <select name="code" >
                                	<option value="">----所有----</option>
					                <option th:each="dict : ${projectlis}" th:text="${dict.name}" th:value="${dict.orderNo}"></option>
					            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gcgl:ygtj:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-success" onclick="print()" >
                    <i class="fa fa-download"></i> 打印
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "gcgl/ygtj";

        $(function() {
            var options = {
                url: prefix + "/listMonth",
                exportUrl: prefix + "/export",
                modalName: "用工统计",
                sortName: "a.code desc",
                sortOrder: "",
                footerStyle: footerStyle,
                showFooter: true,
                pageSize:50,
                pageList:[10, 25, 50],
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'year',
                    title: '年'
                },
                {
                    field: 'month',
                    title: '月'
                },
                {
                    field: 'code',
                    title: '编码'
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'descs',
                    title: '工日',
				    footerFormatter:function (value) {
				    	var sumBalance = 0;
				        for (var i in value) {
				        	sumBalance += parseFloat(value[i].descs);
				        }
				        return "总工日：" + sumBalance;
				    }
                },
                {
                    field: 'jzje',
                    title: '结账金额',
				    footerFormatter:function (value) {
				    	var sumBalance = 0;
				        for (var i in value) {
				        	sumBalance += parseFloat(value[i].jzje);
				        }
				        return "总金额：" + sumBalance;
				    }
                }]
            };
            $.table.init(options);
        });
        
        function footerStyle(column) {
        	return {
        	    jzje: {
        	        css: { color: 'red', 'font-weight': 'normal' }
        	    },
        	    descs: {
        	        css: { color: 'red', 'font-weight': 'normal' }
        	    }
        	}[column.field]
        }
        
        function print(){
        	var month = $("#month").val();
        	if (month == "" || month == undefined) {
                $.modal.alertWarning("请选择查询月份");
                return;
            }
            
            $.modal.openTab('打印',"/gcgl/ygtj/ygtjMonthPrint/"+month);
        }
    </script>
</body>
</html>